<template>
    <div>
        <el-tabs v-model="activeTop" type="border-card">
            <el-tab-pane label="项目设备计划" name="one">
            </el-tab-pane>
            <el-tab-pane label="项目实施计划" name="two">
                <el-table :data="InitWorkPlanTableData" border stripe style="width: 100%">
                    <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
                    <el-table-column fixed prop="ConstructionProcedure" label="项目工序" align="center" show-overflow-tooltip  ></el-table-column>
                    <el-table-column fixed prop="ConstructionContents" label="工序内容" align="center" show-overflow-tooltip  ></el-table-column>
                    <el-table-column prop="TotalQuantity" label="工程总量" align="center" show-overflow-tooltip  ></el-table-column>
                    <el-table-column prop="Price" label="单价" align="center" show-overflow-tooltip  ></el-table-column>
                    <el-table-column prop="Unit" label="单位" align="center" show-overflow-tooltip  ></el-table-column>
                    <el-table-column prop="PlanStartDate" label="计划开始日期" align="center" show-overflow-tooltip>
                        <template slot-scope="slot">
                            {{ frtDate(slot.row.PlanStartDate) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="PlanEndDate" label="计划结束日期" align="center" show-overflow-tooltip>
                        <template slot-scope="slot">
                            {{ frtDate(slot.row.PlanEndDate) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="Planner" label="计划人员" align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="PlanningMaterials" label="计划材料" align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="PlanningMachinery" label="计划机械" align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column fixed="right" label="操作" align="center" width="145px">
                        <template slot-scope="slot">
                            <el-button size="mini" type="success" plain @click="PlanUpdataEvent(slot.row)">修改</el-button>
                            <el-button size="mini" type="danger" plain @click="PlanDelectEvent(slot.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-row>
                    <el-col align="center" style="margin-top: 10px">
                        <el-button type="success" @click="AddProjectPlane_dialog=true">新建计划</el-button>
                    </el-col>
                </el-row>
            </el-tab-pane>
            <el-tab-pane label="项目人员计划" name="three">
                <el-form label-width="120px" style="padding: 20px 0px" ref="ProjectPeopleTableData">
                    <el-table :data="InitPeopleTableData" border stripe style="width: 100%" @selection-change="SelectionChange_event">
                        <el-table-column fixed type="selection" width="50" align="center"></el-table-column>
                        <el-table-column fixed type="index" label="序号" width="50" align="center" :index="indexMethod"></el-table-column>
                        <el-table-column fixed prop="UserName" label="姓名" align="center" show-overflow-tooltip></el-table-column>
                        <el-table-column fixed prop="Type" label="类型" align="center" show-overflow-tooltip>
                            <template slot-scope="slot">
                                <label v-if="slot.row.Type==1">专职</label>
                                <label v-else>兼职</label>
                            </template>
                        </el-table-column>
                        <el-table-column fixed prop="Age" label="年龄" align="center" show-overflow-tooltip>
                            <template slot-scope="slot">
                                <label>{{ slot.row.Age==0?"":slot.row.Age }}</label>
                            </template>
                        </el-table-column>
                        <el-table-column prop="LaborCost" label="劳务费用" align="center" show-overflow-tooltip>
                            <template slot-scope="slot">
                                <label>{{ slot.row.LaborCost ==0?"":slot.row.LaborCost  }}</label>
                            </template>
                        </el-table-column>
                        <el-table-column prop="Skill" label="技能" align="center" show-overflow-tooltip  ></el-table-column>
                        <el-table-column prop="WorkContent" label="工作职责" align="center" show-overflow-tooltip  ></el-table-column>
                        <el-table-column prop="WorkCycle" label="工作周期" align="center" show-overflow-tooltip  ></el-table-column>
                        <el-table-column fixed="right" label="操作" align="center" width="145px">
                            <template slot-scope="slot">
                                <el-button size="mini" type="success" plain @click="PeopleUpdataEvent(slot.row)">修改</el-button>
                                <el-button size="mini" type="danger" plain @click="PeopleDeleteEvent(slot.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-row>
                        <el-col align="center" style="margin-top: 10px">
                            <el-button type="success" @click="AddProjectPeoplePage_dialog=true">新增人员</el-button>
                            <el-button type="success" @click="ProjectPeoplePageTransferEvent">调动申请</el-button>
                        </el-col>
                    </el-row>
                </el-form>
            </el-tab-pane>
            <el-tab-pane label="文件上传" name="four">
                <el-form label-width="160px" style="padding: 20px 0px">
                    <el-table :data="InitFilesTableData" border style="width: 100%" >
                        <el-table-column label="类型" prop="name"></el-table-column>
                        <el-table-column label="内容" prop="content"></el-table-column>
                        <el-table-column label="操作" width="200px">
                            <template slot-scope="slot">
                                <el-row>
                                    <el-col :span="12">
                                        <UploadFileF :btnclass="{ width: 'auto' }"
                                                     :autoupload="true"
                                                     :another-data="{ FileType:slot.row.FileType, 'id': ProjectData.Id, Type:slot.row.Type, Single:true }"
                                                     :showfilelist="false" content="上传"
                                                     ></UploadFileF>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-button size="mini" type="success" @click="DownloadFile(slot.row,'')">下载</el-button>
                                    </el-col>
                                </el-row>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-row>
                        <el-col align="center" style="margin-top: 10px">
                            <UploadFileF :btnclass="{ width: 'auto' }"
                                         :autoupload="true"
                                         :size="medium"
                                         :another-data="{ FileType:2, 'id': ProjectData.Id, Type:256, Single:false  }"
                                         :showfilelist="false" content="其他文件上传"
                            ></UploadFileF>
                        </el-col>
                    </el-row>
                </el-form>
            </el-tab-pane>
        </el-tabs>

        <el-dialog :visible.sync="AddProjectPlane_dialog" title="添加项目实施计划" width="80%" :modal="false" @close="FormresetFields('AddProjectWorkPlan_refs')">
            <el-form :model="ProjectWorkPlan" label-width="140px" :rules="ProjectWorkPlanrules" ref="AddProjectWorkPlan_refs">
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="项目工序" prop="ConstructionProcedure">
                            <el-input v-model="ProjectWorkPlan.ConstructionProcedure"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="工序内容" prop="ConstructionContents">
                            <el-input v-model="ProjectWorkPlan.ConstructionContents"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="工程总量" prop="TotalQuantity">
                            <el-input v-model.number="ProjectWorkPlan.TotalQuantity"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="单价" prop="Price">
                            <el-input v-model.number="ProjectWorkPlan.Price"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="计划开始工期" prop="PlanStartDate">
                            <el-date-picker style="width: 100%" placeholder="计划开始工期"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            v-model="ProjectWorkPlan.PlanStartDate"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="计划结束工期" prop="PlanEndDate">
                            <el-date-picker style="width: 100%" placeholder="计划结束工期"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            v-model="ProjectWorkPlan.PlanEndDate"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="单位" prop="Unit">
                            <el-input v-model="ProjectWorkPlan.Unit"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="计划人员（名）"  prop="Planner">
                            <el-input v-model.number="ProjectWorkPlan.Planner"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="计划材料（数量）"  prop="PlanningMaterials">
                            <el-input v-model.number="ProjectWorkPlan.PlanningMaterials"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="计划机械（台）" prop="PlanningMachinery">
                            <el-input v-model.number="ProjectWorkPlan.PlanningMachinery"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="备注" prop="Remark">
                            <el-input v-model="ProjectWorkPlan.Remark"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col align="center">
                        <el-button type="success" @click="AddSubmit">添加</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="AddProjectPeoplePage_dialog" title="添加项目人员" @close="FormresetFields('AddProjectPeoplePage_refs')" width="80%" :modal="false" >
            <el-form label-width="120px" :model="ProjectPeoplePage" ref="AddProjectPeoplePage_refs" :rules="ProjectPeoplePageRules">
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="类型" prop="Type">
                            <el-select v-model="ProjectPeoplePage.Type" @change="typechangeEvent" style="width: 100%">
                                <el-option :value="1" label="专职"></el-option>
                                <el-option :value="2" label="兼职"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item v-show="TypeOne" label="姓名" prop="Userid">
                            <el-select filterable v-model="ProjectPeoplePage.Userid" style="width: 100%">
                                <el-option v-for="v in $store.state.AllUsers" :value="v.Id" :label="v.UserName"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item v-show="TypeTwo" label="姓名" prop="UserName">
                            <el-input v-model="ProjectPeoplePage.UserName"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-show="TypeTwo">
                    <el-col :span="11" :offset="1">
                        <el-form-item label="年龄" prop="Age">
                            <el-input v-model="ProjectPeoplePage.Age"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="劳务费用" prop="LaborCost">
                            <el-input v-model="ProjectPeoplePage.LaborCost"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="特殊技能" prop="Skill">
                            <el-input v-model="ProjectPeoplePage.Skill"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="工作职责" prop="WorkContent">
                            <el-input v-model="ProjectPeoplePage.WorkContent"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="22" :offset="1">
                        <el-form-item label="工作周期" prop="WorkCycle">
                            <el-input v-model="ProjectPeoplePage.WorkCycle"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col align="center">
                        <el-button @click="AddProjectPeoplePageSubmit" type="success">添加</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="UpdataProjectPlane_dialog.show" title="修改项目工作计划" width="80%" :modal="false">
            <UpdataProjectWorkPlan :project-work-plan="UpdataProjectPlane_dialog.data"></UpdataProjectWorkPlan>
        </el-dialog>

        <el-dialog :visible.sync="UpdataProjectPeoplePage_dialog.show" title="修改项目人员计划" width="80%" :modal="false">
            <UpdataProjectPeoplePage :project-people-page="UpdataProjectPeoplePage_dialog.data"></UpdataProjectPeoplePage>
        </el-dialog>

        <el-dialog :visible="ProjectPeoplePageTransfer_dialog.show" title="添加项目人员调动申请" width="80%" :modal="false">
            <el-form :model="ProjectPeoplePageTransfer_dialog.data" label-width="120px">
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="调入项目">
                            <el-select placeholder="请选择项目" filterable style="width: 100%" v-model="ProjectPeoplePageTransfer_dialog.data.TransferPoject">
                                <el-option v-for="item in AllProject" :value="item.Id" :label="item.ProjectName"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="工作内容">
                            <el-input v-model="ProjectPeoplePageTransfer_dialog.data.TransferPojectContent"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11" :offset="1">
                        <el-form-item label="到岗日期">
                            <el-date-picker style="width: 100%" placeholder="到岗日期"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            v-model="ProjectPeoplePageTransfer_dialog.data.ArriveDate"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="调动原因">
                            <el-input v-model="ProjectPeoplePageTransfer_dialog.data.Reason"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col align="center">
                        <el-button type="success" @click="AddProjectPeoplePageTransferEvent">添加</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
    import UpdataProjectWorkPlan from "./UpdataProjectWorkPlan";
    import UpdataProjectPeoplePage from "./UpdataProjectPeoplePage";
    import UploadFileF from "../UploadFileF";
    import * as publicjs from "../../../public/Scriput/Public"

    export default {
        name: "ProjectPrepare",
        components:{
            UpdataProjectWorkPlan,UpdataProjectPeoplePage,
            UploadFileF,
        },
        props:{
            ProjectData:{
                type:Object,
                required:true,
                default:null,
            },
            AllProject:{
                type:Array,
                required:true,
            }
        },
        data(){
            return{
                activeTop:'two',
                InitWorkPlanTableData:[],
                InitPeopleTableData:[],
                InitFilesTableData:[
                    { name:'施工方案',content:'',Type:4, FileType:2},
                    { name:'项目开工申请报告',content:'',Type:8, FileType:2},
                ],
                AddProjectPlane_dialog:false,
                AddProjectPeoplePage_dialog:false,
                ProjectPeoplePageTransfer_dialog:{
                    show:false,
                    data:{
                        TransferPoject:'',
                        TransferPojectContent:'',
                        ArriveDate:null,
                        Reason:'',
                        ProjectId:0,
                        Type:1,
                        RelationId:'',
                    }
                },
                ProjectPeopleTransfer_dialog:{
                    show:false,
                    data:{}
                },
                UpdataProjectPlane_dialog:{
                    show:false,
                    data:{}
                },

                ProjectWorkPlan:{
                    ConstructionProcedure:'',
                    ConstructionContents:'',
                    TotalQuantity:0,
                    Price:0,
                    PlanStartDate:null,
                    PlanEndDate:null,
                    Unit:'',
                    Planner:0,
                    PlanningMaterials:0,
                    PlanningMachinery:0,
                    Remark:'',
                    ProjectId:'',
                },

                //region 项目人员计划数据
                ProjectPeoplePage:{
                    Type:null,
                    Userid:null,
                    UserName:'',
                    Age:0,
                    LaborCost:0,
                    Skill:'',
                    WorkContent:'',
                    WorkCycle:'',
                    ProjectId:0,
                },
                TypeOne:true,
                TypeTwo:false,
                ProjectPeoplePageRules:{
                    Userid: [{ required:true,message:'请选择人员',trigger:'change' }]
                },
                SelectMore_lis:[],//表格选中项
                UpdataProjectPeoplePage_dialog:{
                    show:false,
                    data:{}
                },
                //endregion

                ProjectWorkPlanrules:{
                    TotalQuantity:[ { type:'number', required:true, message:'请输入数字',trigger: 'blur' } ],
                    Price:[ { type:'number', required:true, message:'请输入数字',trigger: 'blur' } ],
                },

                //region 文件上传
                AnotherData:{
                    FileType:0,
                    id:0,
                    Type:0,
                    Single:true
                },
                //endregion
            }
        },
        created() {
            this.GetAllPrepareData()
            publicjs.http(this.$http,this.$message)
        },
        watch:{
            ProjectData:function () {
                this.GetAllPrepareData()
            }
        },
        methods:{
            //表格数据序列号
            indexMethod(index) {
                return index + 1
            },
            //初始数据加载
            GetAllPrepareData(){
                this.$http.post('Project1/GetAllPrepareData',{ id:this.ProjectData.Id }).then(res=>{
                    this.InitTwo(res.data.projectWorkPlans)
                    this.InitThree(res.data.projectPeople)
                })
            },
            //时间转化
            frtDate(val){
                return val.split(' ')[0]
            },
            //添加表格重置
            FormresetFields(name){
                this.$refs[name].resetFields()
            },

            //region--------------------------项目实施计划---------------------------
            InitTwo(obj){
                this.InitWorkPlanTableData=obj
            },
            //添加项目实施计划
            AddSubmit(){
                this.ProjectWorkPlan.ProjectId = this.ProjectData.Id
                this.$http.post('Project1/AddProjectWorkPlan',{ projectWorkPlan:this.ProjectWorkPlan }).then(res=>{
                    if (res.data.result.IsSuccess){
                        this.$message.success(res.data.result.Msg)
                        this.InitWorkPlanTableData.push(res.data.projectWorkPlan)
                        this.$refs['AddProjectWorkPlan_refs'].resetFields()
                        this.AddProjectPlane_dialog=false
                    }else {
                        this.$message.warning(res.data.result.Msg)
                    }
                })
            },
            //修改项目实施计划
            PlanUpdataEvent(obj){
                this.UpdataProjectPlane_dialog.show=true
                this.UpdataProjectPlane_dialog.data=obj
            },
            //删除项目实施计划
            PlanDelectEvent(obj){
                this.$confirm("你确定要删除吗?",'提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                }).then(()=>{
                    this.$http.post('Project1/DeleteProjectWorkPlan',{ id:obj.Id }).then(res=>{
                        if (res.data.IsSuccess){
                            this.$message.success(res.data.Msg)
                            for (let i=0;i<this.InitWorkPlanTableData.length;i++){
                                if (this.InitWorkPlanTableData[i].Id == obj.Id){
                                    this.InitWorkPlanTableData.splice(i,1)
                                }
                            }
                        }else{
                            this.$message.warning(res.data.Msg)
                        }
                    })
                }).catch(()=>{})
            },
            //endregion

            //region--------------------------项目人员计划 ---------------------------
            InitThree(obj){
                this.InitPeopleTableData=obj
            },
            typechangeEvent(val){
                let _this = this
                switch (val) {
                    case 1:
                        _this.TypeOne=true
                        _this.TypeTwo=false
                        _this.ProjectPeoplePage.Age=0
                        _this.ProjectPeoplePage.LaborCost=0
                        _this.ProjectPeoplePage.Userid=''
                        break;
                    case 2:
                        _this.TypeOne=false
                        _this.TypeTwo=true
                        _this.ProjectPeoplePage.Userid=0
                        break;
                }
            },
            //添加项目人员计划
            AddProjectPeoplePageSubmit(){
                this.ProjectPeoplePage.ProjectId = this.ProjectData.Id
                this.$refs['AddProjectPeoplePage_refs'].validate((vali)=>{
                    if (vali){
                        this.$http.post('Project1/AddProjectPeople',{ projectPeoplePage:this.ProjectPeoplePage }).then(res=>{
                            if (res.data.result.IsSuccess){
                                this.$message.success(res.data.result.Msg)
                                this.InitPeopleTableData.push(res.data.projectPeople)
                                this.AddProjectPeoplePage_dialog=false
                                this.$refs['AddProjectPeoplePage_refs'].resetFields()
                            }else{
                                this.$message.warning(res.data.result.Msg)
                            }
                        })
                    }
                })
            },
            //修改项目人员计划
            PeopleUpdataEvent(obj){
                this.UpdataProjectPeoplePage_dialog.show=true
                this.UpdataProjectPeoplePage_dialog.data=obj
            },
            //删除项目人员计划
            PeopleDeleteEvent(obj){
                this.$confirm("你确定要删除吗?",'提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                }).then(()=>{
                    this.$http.post('Project1/DeleteProjectPeople',{ id:obj.Id }).then(res=>{
                        if (res.data.IsSuccess){
                            this.$message.success(res.data.Msg)
                            for (let i=0;i<this.InitPeopleTableData.length;i++){
                                if (this.InitPeopleTableData[i].Id == obj.Id){
                                    this.InitPeopleTableData.splice(i,1)
                                }
                            }
                        }else{
                            this.$message.warning(res.data.Msg)
                        }
                    })
                }).catch(()=>{})
            },
            //表格数据选择事件
            SelectionChange_event(value) {
                this.SelectMore_lis = value
            },
            //人员调动
            ProjectPeoplePageTransferEvent(){
                if (this.SelectMore_lis.length == 0){
                    this.$message.warning('请选择需要调动的人员')
                }else{
                    this.ProjectPeoplePageTransfer_dialog.show=true
                }
            },
            //添加人员调动
            AddProjectPeoplePageTransferEvent(){
                if (this.ProjectPeoplePageTransfer_dialog.data.TransferPoject == this.ProjectData.Id){
                    this.$message.warning('不能选择当前所在项目')
                    return
                }
                this.ProjectPeoplePageTransfer_dialog.data.ProjectId=this.ProjectData.Id
                this.ProjectPeoplePageTransfer_dialog.data.Type = 1
                let useridlis = this.SelectMore_lis.map(obj=>{ return obj.Id })
                this.ProjectPeoplePageTransfer_dialog.data.RelationId = useridlis.toString()
                this.$http.post('Project1/AddProjectPeopleTransferData',{
                    projectPeopleDeviceTransfer:this.ProjectPeoplePageTransfer_dialog.data
                }).then(res=>{
                    if (res.data.IsSuccess){
                        this.$message.success(res.data.Msg)
                        this.ProjectPeoplePageTransfer_dialog.show=false
                        this.GetAllPrepareData()
                    }else{
                        this.$message.warning(res.data.Msg)
                    }
                })
            },
            //endregion

            //region--------------------------文件上传 ---------------------------
            //文件下载
            DownloadFile(obj,FileName){
                let option = { id: this.ProjectData.Id, FileType: obj.FileType, Type: obj.Type, FileName: FileName }
                publicjs.DownLoadFile(option)
            },
            //endregion
        },
    }
</script>

<style scoped>

</style>
